<!DOCTYPE html>
{% autoescape true %}
<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>
  <body>
    <div align="center">
      <h2>Build Command Statistics - Prototype</h2>
      <p>
        This is an admittedly primitive interface to the build command
        statistics gathered every time a build command (currently just
        build_packages) is run in golo.chromium.org or corp.google.com.
      </p>
      <p>
        Create
        <a href="https://developers.google.com/appengine/docs/python/datastore/gqlreference">GCL queries</a>
        to search the statistics database.  GCL has no SELECT or FROM clauses.  This site
        supports a SQL-like SELECT clause for column filtering, but no FROM clause is
        needed/supported.  If no SELECT clause is given then default columns are selected
        (see below).  A default LIMIT 30 is used unless otherwise specified.
      </p>
    </div>

    <hr>
    <h3>Prepare a new query</h3>
    <form action="/stats" method="get">
      <h5>Write your own query</h5>
      <div><textarea name="query" rows="2" cols="100">{{ user_query }}</textarea></div>
      <div>
        display format:
        <input type="radio" name="format" value="table" checked>table (default)
        <input type="radio" name="format" value="json">json
      </div>
      <div><input type="submit" value="Submit Query"></div>
    </form>

    <form action="/stats" method="get">
      <h5>Select an example query</h5>
      <div>
        <select name="query">
          {% for example_query in example_queries %}
            <option>{{ example_query }}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        display format:
        <input type="radio" name="format" value="table" checked>table (default)
        <input type="radio" name="format" value="json">json
      </div>
      <div><input type="submit" value="Submit Query"></div>
    </form>

    <hr>
    <div><h3>Query results</h3></div>
    <div>For query: <b>{{ user_query }}</b></div>
    <p/>
    {% if error_msg %}
    <b><font color="red">{{ error_msg }}</font></b>
    {% else %}
    <table border="1">
      {% for row in results_table %}
      <tr>
        {% for cell in row %}
        <td>{{ cell }}</td>
        {% endfor %}
      </tr>
      {% endfor %}
    </table>
    {% endif %}
    <p/>

    <hr>
    <div><h3>Database columns available</h3></div>
    <ul>
    {% for col in column_list %}
    <li>{{ col }}</li>
    {% endfor %}
    </ul>
    <hr>
    <div align="center">
      Signed in as <b>{{ user_email }}</b>
    </div>
  </body>
</html>
{% endautoescape %}
